package cn.strive.eams.fixedassets.service.impl;

import cn.strive.eams.base.response.JsonResult;
import cn.strive.eams.fixedassets.mapper.FixedassetsMapper;
import cn.strive.eams.fixedassets.pojo.dto.FixedassetsQuerry;
import cn.strive.eams.fixedassets.pojo.dto.FixedassetsSaveParam;
import cn.strive.eams.fixedassets.pojo.dto.FixesAssetsQuery;
import cn.strive.eams.fixedassets.pojo.entity.Fixedassets;
import cn.strive.eams.fixedassets.pojo.vo.FixedassetsVO;
import cn.strive.eams.fixedassets.service.FixedassetsService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class FixedassetsServiceImpl implements FixedassetsService {
    @Autowired
    FixedassetsMapper fixedassetsMapper;

    @Override
    public List<FixedassetsVO> selectFixedassets(FixedassetsQuerry fixedassetsQuerry) {
        log.debug("查询所有资产信息:fixedassetsQuerry={}",fixedassetsQuerry);
        List<FixedassetsVO> list = fixedassetsMapper.selectFixedassets(fixedassetsQuerry);
        return list;
    }
    @Override
    public void saveFixedassets(FixedassetsSaveParam fixedassetsSaveParam){
        log.debug("保存资产信息:fixedassetsSaveParam={}",fixedassetsSaveParam);
        Fixedassets fixedassets = new Fixedassets();
        BeanUtils.copyProperties(fixedassetsSaveParam,fixedassets);
        if (fixedassets.getId() == null){
            fixedassets.setCreateTime(new Date());
            fixedassetsMapper.insert(fixedassets);
        }else {
            fixedassets.setUpdateTime(new Date());
            fixedassetsMapper.update(fixedassets);
        }
    }
    @Override
    public void deleteFixedassets(Long id) {
        log.debug("删除资产信息:id={}",id);
        fixedassetsMapper.delete(id);
    }

    @Override
    public List<FixedassetsVO> selectHomeAsset(FixesAssetsQuery fixesAssetsQuery) {
        log.debug("查询房间的资产信息,参数:{}",fixesAssetsQuery);
        return fixedassetsMapper.selectHomeAsset(fixesAssetsQuery);
    }

    @Override
    public List<FixedassetsVO> selectById(FixedassetsQuerry fixedassetsQuerry) {
        log.debug("查询所有资产信息:fixedassetsQuerry={}",fixedassetsQuerry);
        List<FixedassetsVO> list = fixedassetsMapper.selectById(fixedassetsQuerry);
        log.debug("返回给前端的数据: {}", list);
        return list;

    }
}